﻿namespace MVVMBasedDialogs.Control
{
    using System.Windows.Controls;
    using System.Windows;

    class ConventionContentControl : ContentControl
    {
        protected override void OnContentChanged(object oldContent, object newContent)
        {
            base.OnContentChanged(oldContent, newContent);

            string viewModelName = newContent.GetType().Name;
            string templateName = string.Format("{0}Template", 
                viewModelName.Substring(0, viewModelName.IndexOf("ViewModel")));
            this.ContentTemplate = 
                (DataTemplate)Application.Current.Resources[templateName];
        }
    }
}
